package org.robot.scm.platform.server.handler;

import com.sun.net.httpserver.HttpExchange;
import com.sun.net.httpserver.HttpHandler;
import java.io.IOException;
import java.util.List;
import lombok.NoArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.robot.scm.pojos.platform.sqlite.ExpFile;
import org.robot.scm.utils.JsonHelper;
import org.robot.scm.utils.SQLiteUtil;

/**
 * 导出文件列表
 */
@Slf4j
@NoArgsConstructor
public class ExpListHandler extends BaseHandler implements HttpHandler {

    @Override
    public String getUri() {
        return "/explist";
    }

    @Override
    public void handle(HttpExchange exchange) throws IOException {
        if (!exchange.getRequestMethod().equalsIgnoreCase("POST")) {
            sendFailureResponse(exchange, "请求非法");
            return;
        }
        List<ExpFile> files = SQLiteUtil.query("select * from exp_file order by file_id desc", ExpFile.class);
        sendSuccessResponse(exchange, "查询成功", JsonHelper.toJSONString(files));
    }
}
